#ifndef COMMON_APPLICATION_H
#define COMMON_APPLICATION_H

#include <glad\glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include "GuiLayer.h"
#include "SampleSelector.h"
#include "Log.h"
namespace ShaderLab {

struct WindowParam {
    WindowParam(std::string name = "Shader Lab", int width = 1280, int height = 960, bool isFullScreen = true)  
        : mWindowName(name), mWidth(width), mHeight(height), mIsFullScreen(isFullScreen)
    {}
    std::string mWindowName;
    int mWidth;
    int mHeight;
    bool mIsFullScreen;
};

static void glfw_error_callback(int error, const char* description) {
    fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GLFW_TRUE);
}

class Application {
 public:
    ~Application();
    void Run();

    static Application* GetInstance();
    GLFWwindow* GetWinowHandle();
    GuiLayer* GetGuiHandle();
    void SetParam(WindowParam param);
    void InitApplication();
	int GetHeight() const { return mWindowParam.mHeight; }
	int GetWidth() const { return mWindowParam.mWidth; }
 private:
     Application();
     bool CreateApplicationWindow();
     void DestroyWindow();
 private:
     GLFWwindow* mWindowHandle = nullptr;
     GuiLayer* mGui = nullptr;
     WindowParam mWindowParam;
     bool mIsRunning = false;
     ImVec4 clear_color = ImVec4(0.144f, 0.668f, 0.931f, 1.000f);
     SampleSelector* mSelector = nullptr;
     static Application* msInstance;
	 float currTime = 0.0f,preTime = 0.0f;
};

}
#endif // !COMMON_APPLICATION_H


